//-------------------------------------------------------------------
//	Copyright (c) 2010-2012  Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_FRAME_ANIMATION_H
#define _UX_FRAME_ANIMATION_H

#include "IBaseAnimation.h"

namespace Engine
{
namespace Resources
{

	//
	// Frame Animation
	//

	class _EXPORT_ CFrameAnimation : public IBaseAnimation
	{
		friend class CFrameAnimAnimator;

	protected:
		typedef array< TFrameAnimData::TTrackInfo >		track_array_t;
		
	protected:
		track_array_t	_aTracks;
		uint32_array_t	_aTrackFrames;
		float			_fFrameRate;

	protected:
		CFrameAnimation(const char *pFileName);
		~CFrameAnimation();

		virtual bool _Replace(CResource *pRes);
		virtual bool _Load(IFilePtr pFile, uint uSize);
		virtual bool _Save(IFilePtr pFile);
		virtual bool _Reload(IFilePtr pFile, bool bRecursive);

	public:
		bool Create(const TFrameAnimData &sAnim);
		
		float GetFrameRate()					const		{ return _fFrameRate; }
		uint  GetTrackFramesCount(uint uTrack)	const		{ return _aTracks[ uTrack ].uCount; }


		// IBaseAnimation //
		virtual bool GetAnimator(const CResourcePtr &pMesh, const array<IMaterialPtr> &aMaterials, IBaseModelAnimatorPtr &pAnimator);

		// CResource //
		virtual void Destroy();
		virtual bool IsValid() const;

		virtual e_resource::type		GetType()		 const	{ return e_resource::FRAME_ANIMATION; }


		static CFrameAnimationPtr s_CreateFrameAnimation(const char *pFileName);
	};



	//
	// Frame Animation Animator
	//
	/*
	class _EXPORT_ CFrameAnimAnimator : public IBaseModelAnimator
	{
	protected:
		CMultiMeshModelPtr		_pModel;
		CFrameAnimationPtr		_pAnim;
		uint					_uTrack;
		uint					_uFrame;
		float					_fTime;
		bool					_bLooping;
		
	protected:
		CFrameAnimAnimator(const char *pFileName);
		~CFrameAnimAnimator();

		virtual bool _Replace(CResource *pRes);
		virtual bool _Load(IFilePtr pFile, uint uSize);
		virtual bool _Save(IFilePtr pFile);
		virtual bool _Reload(IFilePtr pFile, bool bRecursive);

		static void _s_DrawSubMesh(void *, void *);

	public:
		bool Create(const CMultiMeshPtr &, const CFrameAnimationPtr &, const array<IMaterialPtr> &);
		bool Create(const TMesh &, const TMeshAnimation &, const TMeshMaterial &);

		// IBaseModelAnimator //
		virtual bool Render(const TROParams<float>  &sParams, TCameraRenderQueue *pCRQ);
		virtual bool Render(const TROParams<double> &sParams, TCameraRenderQueue *pCRQ);
		virtual bool Update(float fTimeDelta);
		virtual bool GetBoundingBox(aabb_f &sBBox);
		virtual bool SetTracksCurrent(const uint32 *pTracks, uint uCount, uint uStartFrame);
		virtual bool SetCurrentFrame(uint uTrack, uint uFrame);
		virtual void SetLooping(bool bLooping);
		virtual bool GetLooping() const;
		virtual bool GetAnimation(CResourcePtr &);
		virtual bool GetMesh(CResourcePtr &);
		virtual bool GetMaterials(array<IMaterialPtr> &aMaterials);

		// CResource//
		virtual void			Destroy();
		virtual bool			Compare(CResource *pRes);
		virtual bool			IsValid() const;
		virtual e_resource::type	GetType() const		{ return e_resource::FRAME_ANIMATOR; }

		static CFrameAnimAnimatorPtr s_CreateFrameAnimAnimator(const char *pFileName);
	};
	*/
//-------------------------------------------------------------------

}	// Resources
}	// Engine

#endif	// _UX_FRAME_ANIMATION_H